#include "HeadFiles.h"

BulletManager* BulletManager::instance = nullptr;

BulletManager* BulletManager::Instance()
{
	if (instance == nullptr)
		instance = new BulletManager();
	return instance;
}

void BulletManager::Show()
{
	for (list<CBullet>::iterator iter = bullet_list.begin(); iter != bullet_list.end(); iter++)
	{
		iter->Show();
	}
}

void BulletManager::Update()
{
	for (list<CBullet>::iterator iter = bullet_list.begin(); iter != bullet_list.end(); iter++)
	{
		iter->Update();
		COORD* temp_pos = iter->ReturnPos();
		if (temp_pos->X > weith || temp_pos->Y > height)
		{
			list<CBullet>::iterator temp_iter = iter;
			iter--;
			DelBullet(temp_iter);
		}
	}
}

void BulletManager::AddBullet(COORD pos, Direction dir)
{
	CBullet bullet(pos,dir);
	bullet_list.push_back(bullet);
}

void BulletManager::DelBullet(list<CBullet>::iterator bullet)
{
	bullet_list.erase(bullet);
}

list<CBullet>::iterator BulletManager::ReturnHead()
{
	return bullet_list.begin();
}
list<CBullet>::iterator BulletManager::ReturnEnd()
{
	return bullet_list.end();
}
